package com.lei.order.controller;


import com.lei.order.service.PayLogService;
import com.lei.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author 熊磊
 * @since 2020-06-16
 */
@RestController
@RequestMapping("/edu/paylog")
public class PayLogController {
    @Autowired
    private PayLogService payLogService;

    @GetMapping("/createNative/{orderNo}")
    public Result createNative(@PathVariable("orderNo")String orderNo){
        Map map =payLogService.createNative(orderNo);
        return Result.ok().data(map);
    }

    // 查询订单支付状态
    @GetMapping("/queryPayStatus/{orderNo}")
    public Result queryPayStatus(@PathVariable("orderNo") String orderNo){
        Map<String,String> map = payLogService.queryPayStatus(orderNo);
        if (map==null){
            return Result.error().message("支付出错");
        }
        if (map.get("trade_state").equals("SUCCESS")){
            //更新订单表状态

            //支付表添加数据
            payLogService.updateOrderStatus(map);
            return Result.ok();
        }
        return Result.ok().code(25000).message("支付未完成");
    }
}

